var worker=new Worker("./worker.js");
worker.onmessage=function(event){
    // console.log("子工作进程返回结果",event);
    // console.log(event.data)

    const regex = /\[(.*?)\]/g;  
    const matches = event.data.match(regex);  

    const current=document.querySelector("#current")
    const sum=document.querySelector("#sum")

    const cnow="["+getCurrentDateTime()+"]"
    current.textContent=matches[0]=="[]"?cnow:matches[0]
    sum.textContent=matches[1]
}

worker.onerror=function(error){
    console.error(error);
}

worker.postMessage("hello worker !!!!")


function jcclose(){
    console.log(worker,"结束进程");
    worker.terminate()
}

function getCurrentDateTime() {  
    // 创建一个新的 Date 对象，表示当前日期和时间  
    const now = new Date();  
  
    // 获取年、月、日、时、分、秒  
    const year = now.getFullYear();  
    const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要加1，并补零  
    const day = String(now.getDate()).padStart(2, '0'); // 补零  
    const hours = String(now.getHours()).padStart(2, '0'); // 补零  
    const minutes = String(now.getMinutes()).padStart(2, '0'); // 补零  
    const seconds = String(now.getSeconds()).padStart(2, '0'); // 补零  
  
    // 组合成字符串并返回  
    return`${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;  
}